package cn.imvc.app.jobs;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.dom4j.DocumentException;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Goods;
import cn.imvc.app.entities.PushMessage;
import cn.imvc.app.models.BiLogisticsMateModel;
import cn.imvc.app.models.GoodsSkuModel;
import cn.imvc.app.models.PushMessageModel;
import cn.imvc.app.models.StorageOrderModel;
import cn.imvc.app.repositories.GoodsLimitTimeRepository;
import cn.imvc.app.repositories.GoodsRepository;
import cn.imvc.app.repositories.PushMessageRepository;
import cn.imvc.app.repositories.StorageOrderRepository;
@DisallowConcurrentExecution
public class MessageQuarz{
	@Autowired
	PushMessageRepository pushMessageRepository;
	@Autowired
	PushMessageModel pushMessageModel;
	
	/**
	 * 自动推送消息(10分钟)
	 * @param context
	 */
	public void autoPushNewMessage(JobExecutionContext context) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowStr = dateFormat.format(new Date());
		//查询尚未发送的通知
		List<PushMessage> pushMessages = pushMessageRepository.findAllJpql("select ps from PushMessage ps where ps.time < '"+nowStr
				+"' and ps.state = 0");
		Iterator<PushMessage> iterator = pushMessages.iterator();
		while (iterator.hasNext()) {
			PushMessage pushMessage = (PushMessage) iterator.next();
			pushMessageModel.updatePushMessage(pushMessage);
		}
	}
}
